/**
 *
 */
package com.feizhi.common.search.index.action;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.index.Term;
import org.springframework.stereotype.Component;

import com.feizhi.common.search.exception.SearchException;
import com.feizhi.common.search.index.IndexConstants;
import com.feizhi.common.search.index.LuceneWork;

/**
 * @author shuaqiu
 */
@Component
public class PurgeAllIndexAction extends AbstractIndexAction implements IndexAction {

    private static final Log LOG = LogFactory.getLog(PurgeAllIndexAction.class);

    @Override
    public void performAction(final LuceneWork work) {
        final Class<?> entityType = work.getEntityType();
        LOG.trace("purge all Lucene index using IndexWriter for type: " + entityType);
        try {
            final Term term = new Term(IndexConstants.TYPE_CLASS, entityType.getName());
            writer.deleteDocuments(term);
        } catch (final Exception e) {
            throw new SearchException("Unable to purge all from Lucene index: " + entityType, e);
        }
    }

}
